package com.gjj.abox.account.viewHolder;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

/**
 * Created by DWCloud on 2016/4/1.
 */
public class RecyclerCommonViewHolder extends RecyclerView.ViewHolder {
    private final SparseArray<View> mViews;
    private  View mConvertView;

    public RecyclerCommonViewHolder(View itemView) {
        super(itemView);
        this.mViews = new SparseArray<View>();
        this.mConvertView = itemView;
        mConvertView.setTag(this);
    }


    public <T extends View> T getView(int viewId) {

        View view = mViews.get(viewId);
        if (view == null) {
            view = mConvertView.findViewById(viewId);
            mViews.put(viewId, view);
        }
        return (T) view;
    }

    /**
     * 为TextView设置字符串
     *
     * @param viewId
     * @param text
     * @return
     */
    public RecyclerCommonViewHolder setText(int viewId, String text) {
        TextView view = getView(viewId);
        view.setText(text);
        return this;
    }

    public RecyclerCommonViewHolder getConvertView() {
        return this;
    }
}
